package com.zyddd.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 自定义元数据对象处理器
 * 公共字段自动填充
 * */
@Component
public class MyMetaObjectHandle implements MetaObjectHandler {
    private static final DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createTime", sdf.format(new Date()));
        metaObject.setValue("updateTime", sdf.format(new Date()));
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateTime", sdf.format(new Date()));
    }
}
